//
//  SEGMyProfileHeaderViewCell.m
//  ExcellentHome
//
//  Created by 刘山 on 16/11/22.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "SEGMyProfileHeaderViewCell.h"

@implementation SEGMyProfileHeaderViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    [self.contentView addSubview:self.picImageView];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.ContentLabel];
    [self.contentView addSubview:self.picImageView1];
    [self.contentView addSubview:self.levelimageView];

    [self.picImageView1 setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_more_gray")]];

    [self.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [self.titleLabel setTextColor:kColor_1];

    [self.ContentLabel setFont:[UIFont systemFontOfSize:16]];
    [self.ContentLabel setTextColor:kColor_1];
    [self.ContentLabel setTextAlignment:NSTextAlignmentRight];

    [self.picImageView setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"headimg96")]];
    self.picImageView.layer.cornerRadius = 5.f;
    self.picImageView.layer.masksToBounds = YES;
}

- (void)setCellType:(MyProfileHeaderType)cellType
{
    switch (cellType) {
    case MyProfileHeaderType_NORMAL: {
        [self ConstraintsUI_NORMAL];
    } break;
    case MyProfileHeaderType_HEAD: {
        [self ConstraintsUI_HEAD];
    } break;

    default:
        break;
    }
}

- (void)ConstraintsUI_NORMAL
{
    [self.picImageView setHidden:YES];
    [self.titleLabel setHidden:NO];

    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker* make) {
        make.top.equalTo(self.contentView).mas_offset(14);
        make.left.equalTo(self.contentView).mas_offset(15);
    }];

    if (self.tag == 999) {// 适配有没有向右展开箭头的布局
        
        [self.ContentLabel mas_remakeConstraints:^(MASConstraintMaker* make) {
            make.left.equalTo(self.contentView).mas_offset(99);
            make.top.equalTo(self.contentView).mas_offset(14);
            make.right.mas_offset(-15);
            make.bottom.greaterThanOrEqualTo(self.titleLabel.mas_bottom);
            // iOS10 以上的适配
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
                make.bottom.equalTo(self.contentView).mas_offset(-14);
            }
        }];
        
    }else if (self.tag == 888){
        [self.picImageView1 mas_remakeConstraints:^(MASConstraintMaker* make) {
            make.right.equalTo(self.contentView).mas_offset(-15);
            make.centerY.equalTo(self.titleLabel);
            make.size.mas_equalTo(CGSizeMake(8, 14.5));
        }];
        
        [self.ContentLabel mas_remakeConstraints:^(MASConstraintMaker* make) {
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.levelimageView.mas_left).mas_offset(-3);
        }];
        
        [self.levelimageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.ContentLabel.mas_right).mas_offset(3);
            make.centerY.equalTo(self.contentView);
            make.right.equalTo(self.picImageView1.mas_left).mas_offset(-10);
            make.width.mas_equalTo(16);
            make.height.mas_equalTo(16);
        }];
        
    }else  if (self.tag == 777) {
        [self.picImageView1 mas_remakeConstraints:^(MASConstraintMaker* make) {
            make.right.equalTo(self.contentView).mas_offset(-15);
            make.centerY.equalTo(self.titleLabel);
            make.size.mas_equalTo(CGSizeMake(8, 14.5));
        }];
        
        [self.ContentLabel mas_remakeConstraints:^(MASConstraintMaker* make) {
            make.left.equalTo(self.contentView).mas_offset(99);
            make.top.equalTo(self.contentView).mas_offset(14);
            make.right.equalTo(self.picImageView1.mas_left).mas_offset(-10);
            make.bottom.greaterThanOrEqualTo(self.titleLabel.mas_bottom);
            // iOS10 以上的适配
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
                make.bottom.equalTo(self.contentView).mas_offset(-14);
            }
        }];
    }else if (self.tag == 666){
        
        [self.picImageView1 mas_remakeConstraints:^(MASConstraintMaker* make) {
            make.right.equalTo(self.contentView).mas_offset(-15);
            make.centerY.equalTo(self.titleLabel);
            make.size.mas_equalTo(CGSizeMake(8, 14.5));
        }];
        
        [self.ContentLabel mas_remakeConstraints:^(MASConstraintMaker* make) {
            make.left.equalTo(self.contentView).mas_offset(99);
            make.top.equalTo(self.contentView).mas_offset(14);
            make.right.equalTo(self.picImageView1.mas_left).mas_offset(-10);
            make.bottom.greaterThanOrEqualTo(self.titleLabel.mas_bottom);
            // iOS10 以上的适配
            if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
                make.bottom.equalTo(self.contentView).mas_offset(-14);
            }
        }];
       
    }
    
    //SAM:iOS10兼容-cell
    [self.contentView mas_remakeConstraints:^(MASConstraintMaker* make) {
        // iOS10 以上的适配
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 10.0) {
            make.left.top.right.equalTo(self);
            make.bottom.equalTo(self.ContentLabel.mas_bottom).mas_offset(14);
        }else{
            make.edges.equalTo(self);
        }
        make.height.mas_equalTo(44);
    }];
    
}

- (void)ConstraintsUI_HEAD
{

    [self.picImageView setHidden:NO];
    [self.titleLabel setHidden:NO];
    
    [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker* make) {
//        make.top.equalTo(self.contentView).mas_offset(14);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.centerY.equalTo(self.contentView);
    }];

    [self.picImageView mas_remakeConstraints:^(MASConstraintMaker* make) {
        make.width.mas_equalTo(48);
        
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
            make.height.mas_equalTo(48).priorityHigh();
        }else{
            make.height.mas_equalTo(48);
        }
        
        make.top.equalTo(self.contentView).mas_offset(9);
//        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.picImageView1.mas_left).mas_offset(-10);
        // iOS10 以上的适配
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 10.0) {
            make.bottom.equalTo(self.contentView).mas_offset(-9);
        }
    }];

    [self.picImageView1 mas_remakeConstraints:^(MASConstraintMaker* make) {
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.centerY.equalTo(self.picImageView);
        make.size.mas_equalTo(CGSizeMake(8, 14.5));
    }];

    //SAM:iOS10兼容-cell
    [self.contentView mas_remakeConstraints:^(MASConstraintMaker* make) {
        // iOS10 以上的适配
        if ([[[UIDevice currentDevice] systemVersion] floatValue] < 10.0) {
            make.left.top.right.equalTo(self);
            make.bottom.equalTo(self.picImageView.mas_bottom).mas_offset(9);
        }else{
            make.edges.equalTo(self);
        }
       
    }];
}

#pragma mark - getter
- (UIImageView*)picImageView
{
    if (!_picImageView) {
        _picImageView = [[UIImageView alloc] init];
        _picImageView.contentMode = UIViewContentModeScaleAspectFill;
        [_picImageView setClipsToBounds:YES];
    }
    return _picImageView;
}

- (UILabel*)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
    }
    return _titleLabel;
}

- (UILabel*)ContentLabel
{
    if (!_ContentLabel) {
        _ContentLabel = [[UILabel alloc] init];
    }
    return _ContentLabel;
}

- (UIImageView*)picImageView1
{
    if (!_picImageView1) {
        _picImageView1 = [[UIImageView alloc] init];
        _picImageView1.contentMode = UIViewContentModeScaleAspectFill;
        [_picImageView1 setClipsToBounds:YES];
    }
    return _picImageView1;
}

- (UIImageView*)levelimageView
{
    if (!_levelimageView) {
        _levelimageView = [[UIImageView alloc] init];
    }
    return _levelimageView;
}
@end
